package server.business;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.core.action.TimeAction;

import server.business.entity.Notice;

/**
 * 信息系统
 * gm全局广播
 * @author King
 *
 */
public class InformationManager extends TimeAction
{
	public InformationManager() {
		super(1000);
	}


	private Map<Integer, InformationData> noticeMap = new HashMap<Integer, InformationData>();
	
	
	public Map<Integer, InformationData> getNoticeMap() {
		return noticeMap;
	}

	public void setNoticeMap(Map<Integer, InformationData> noticeMap) {
		this.noticeMap = noticeMap;
	}

	@Override
	public void executeOnTime() throws Exception 
	{
		long now = getCurTime();
		
		Iterator<Map.Entry<Integer, InformationData>> it = noticeMap.entrySet().iterator();
		while(it.hasNext())
		{
			Map.Entry<Integer, InformationData> entry = it.next();
			//已经到删除时间了
			if(entry.getValue().getCloseDate().getTime()>now)
			{
				it.remove();
				continue;
			}
			if(now>entry.getValue().getNextNoticeTime())
				continue;
			entry.getValue().send();
		}
	}
	
}
